import { defineComponent, reactive, onMounted } from 'vue'
import Draw from './draw'
import { buildingType } from '@/public/request/http'

export default defineComponent({
  components: {
    Draw
  },
  setup() {
    const cdata = reactive({
      category: [
      ],
      lineData: [
      ],
      barData: [
      ],
      rateData: []
    })

    // methods
    // const setData = async () => {
    //   const res = await buildingType()
    //   cdata.category = []
    //   cdata.barData = []
    //   res.forEach(element => {
    //     cdata.category.push(element.buildingTypeName)
    //     cdata.barData.push(element.totalCount)
    //   })
      
    // }
    const setData = () => {
      cdata.category = [
        '教学楼',
        '实验楼',
        '办公楼',
        '食堂',
        '健身室'
      ]
      cdata.barData = [
        9,
        3,
        2,
        1,
        1
      ]
    }

    // 生命周期
    onMounted(() => {
      setData()
    })

    return () => {
      return <div>
        <Draw cdata={cdata} />
      </div>
    }
  }
})